<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="crud.queryInput.value"
          clearable
          placeholder="输入搜索内容"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="crud.queryInput.type"
          clearable
          placeholder="类型"
          class="filter-item"
          style="width: 130px"
        >
          <el-option
            v-for="item in queryTypeOptions"
            :key="item.key"
            :label="item.display_name"
            :value="item.key"
          />
        </el-select>
        <el-date-picker
          v-model="query.planFinishTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd"
          start-placeholder="起始时间"
          end-placeholder="结束时间"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <working-staff-dialog :crud="crud" :is-visible="isVisible" :current-task-i-d="currentTaskID" @dialogCancel="dialogCancel" />
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        :row-class-name="rowClassSequenceNo"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('sequence')" prop="sequence" label="序号" width="80" />
        <el-table-column v-if="columns.visible('projectName')" prop="projectName" label="项目名称" />
        <el-table-column v-if="columns.visible('stageName')" prop="stageName" label="阶段名称" />
        <el-table-column
          v-if="columns.visible('simpleDescribe')"
          prop="simpleDescribe"
          label="任务简要描述"
          width="400"
        />
        <el-table-column
          v-if="columns.visible('planFinishTime')"
          prop="planFinishTime"
          label="计划完成时间"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.planFinishTime,'{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('type')" prop="type" label="任务类型" />
        <el-table-column v-if="columns.visible('workerNo')" prop="workerNo" label="已分配人数" />
        <el-table-column v-if="columns.visible('workState')" prop="workState" label="当前进度" />
        <el-table-column
          v-permission="['admin','projectAllTaskView:edit']"
          fixed="right"
          label="人员分配"
          width="80px"
          align="center"
        >
          <template slot-scope="scope">
            <el-button v-permission="['admin','projectAllTaskView:edit']" :loading="crud.status.cu === 2" size="mini" type="primary" icon="el-icon-edit-outline" @click="openEdit(scope.row)" />
          </template>
        </el-table-column>
        <el-table-column
          v-if="false"
          v-permission="['admin','projectAllTaskView:edit']"
          label="任务进度填报"
          width="100px"
          align="center"
        >
          <template slot-scope="scope">
            <el-button v-permission="['admin','projectAllTaskView:edit']" :loading="crud.status.cu === 2" size="mini" type="primary" icon="el-icon-edit" @click="openEdit(scope.row)" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudProjectAllTaskView from '@/api/projectAllTaskView'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import WorkingStaffDialog from './workingstaffdialog.vue'
// crud交由presenter持有
const defaultCrud = CRUD({ title: '全部任务视图', url: 'api/projectAllTaskView', sort: 'id,desc', crudMethod: { ...crudProjectAllTaskView }, optShow: { add: false, edit: true, del: false, download: true }})
const defaultForm = { id: null, projectId: null, stageId: null, planFinishTime: null, type: null, projectName: null, stageName: null, simpleDescribe: null, workerNo: null, workState: null }
export default {
  name: 'ProjectAllTaskView',
  components: { pagination, crudOperation, rrOperation, WorkingStaffDialog },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      isVisible: false,
      currentTaskID: 't0',
      currentStaffInfo: {},
      workList: {},
      workShowListLeft: [],
      workShowListRight: [],
      permission: {
        add: ['admin', 'projectAllTaskView:add'],
        edit: ['admin', 'projectAllTaskView:edit'],
        del: ['admin', 'projectAllTaskView:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'projectId', display_name: '项目系统编号' },
        { key: 'type', display_name: '任务类型' },
        { key: 'projectName', display_name: '项目名称' },
        { key: 'stageName', display_name: '阶段名称' },
        { key: 'simpleDescribe', display_name: '任务简要描述' }
      ],
      pageCount: 0
    }
  },
  created() {
    this.crud.query.type = null
    this.crud.queryInput.value = null
    this.crud.query = {}
    // 设置默认搜索条件
    if (this.$route.query.mode === 'ONE') {
      this.crud.queryInput.type = 'projectId'
      this.crud.queryInput.value = this.$route.query.projectId
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      if (this.pageCount === 0) {
        if (this.$route.query.mode === 'ONE') {
          this.crud.queryInput.type = 'projectId'
          this.crud.queryInput.value = this.$route.query.projectId
        }
        this.pageCount = this.pageCount + 1
      }
      if (this.crud.queryInput.type && this.crud.queryInput.value) {
        this.crud.query[this.queryInput.type] = this.queryInput.value
      }
      return true
    },
    rowClassSequenceNo({ row, rowIndex }) {
      // 把每一行的索引放进row.id
      row.sequence = rowIndex + 1
    },
    openEdit(data) {
      this.isVisible = true
      this.currentTaskID = data.id // 形如t3这样的，t开头为任务，i开头为问题
      console.log(this.crud)
      this.crud.toEdit(data)
    },
    dialogCancel(isVisible) {
      this.isVisible = isVisible
    }
  }
}
</script>

<style>
.member .el-transfer-panel {
  width: 165px;
  height: 300px;
}
.member .el-transfer-panel__list.is-filterable {
  width: 160px;
  height: 300px;
}
.member .el-transfer__button {
  width: 40px;
  display: flex;
}
.member .el-transfer__buttons {
  margin: 0px;
  padding: 0px;
}
</style>
